<?php
include_once "header.php";


$daftar_sifat = new Daftar_sifat_surat();
$sifat = $daftar_sifat->getAll();

$cek_field="";

if (ISSET($_POST["tambah_sm"])){

	if($_POST['nomor']=="" || $_POST['tgl']=="" || $_POST['hal']=="" || $_POST['sifat']=="" || $_POST['asal']==""){
		
		$cek_field = "Peringatan: Silahkan isikan seluruh data yang tersedia.";
	
	} else {
		$daftar_surat_masuk = new Daftar_surat_masuk();
		$surat_masuk = new Surat_masuk();
		$surat_masuk->setNomor($_POST['nomor']);
		$surat_masuk->setTgl($_POST['tgl']);
		$surat_masuk->setHal($_POST['hal']);
		$surat_masuk->setSifat($_POST['sifat']);
		$surat_masuk->setLampiran($_POST['lampiran']);
		$surat_masuk->setAsal($_POST['asal']);
		$surat_masuk->setPenerima($_SESSION['nip']);
		$surat_masuk->setWaktu_terima(date("Y-m-d H:i:s"));
		//$surat_masuk->setNo_agenda($daftar_surat_masuk->getLastAgenda() + 1);
		$daftar_surat_masuk->add($surat_masuk);
		
		header("Location:surat_masuk.php");
		}
	
}
?>

<div id="container">
	<div id="errorcont">
		<?php echo $cek_field;
		?>
	</div>
	<div id="maincont">
		<?php include_once "menu_samping.php"; ?>
		<div id="mainright">
			<div id="title">
			Surat Masuk > Rekam
			</div>
			<div id="body">
			</br>
			<form name="form1" method="POST" action="rekam_sm.php">
			<input type="hidden" name="tambah_sm">
			<table  cellspacing=0 cellpadding=4>		
				<tr>
					<td>Nomor</td>
					<td>:</td>
					<td><input type="text" name="nomor" id="nomor" size=64 ></td>
				</tr>
				<tr>				
					<td>Tanggal</td>
					<td>:</td>
					<td><input type="text" name="tgl" id="tgl" ></td>
				</tr>
				<tr>	
					<td>Hal</td>
					<td>:</td>
					<td><input type="text" name="hal" id="hal" size=100></td>
				</tr>
				<tr>	
					<td>Sifat</td>
					<td>:</td>
					<td>
					<select name="sifat">
					<?php
						foreach($sifat as $Sifat){
					?>
							<option value="<?php echo $Sifat->getId();?>"><?php echo $Sifat->getSifat();?></option>
					
						<?php }?>
					
					</select>
					</td>
				</tr>
				<tr>	
					<td>Lampiran</td>
					<td>:</td>
					<td><input type="text" name="lampiran" ></td>
				</tr>
				<tr>	
					<td>Asal</td>
					<td>:</td>
					<td><input type="text" name="asal" size=64 ></td>
				</tr>
				<tr>	
					<td>Penerima</td>
					<td>:</td>
					<td><input readonly="yes" type="text" name="penerima" id="penerima" value="<?php echo $_SESSION['nama']; ?>"></td>
				</tr>
				
					<input type="hidden" name="waktu_terima" >
					
					<input type="hidden" name="no_agenda" >
					
			</table>
			<br>
			<input type="submit" value="Simpan"> 
			<input type="button" value="Batal" onClick="window.location.href='surat_masuk.php'">
			</form>
						
			</div>
        </div>
	</div>
</div>
<?php
	include_once "footer.php";
?>

<script type="text/javascript">
	$(function() { 
	$("#tgl").datepicker({dateFormat: "yy-mm-dd",
											buttonImage:'jquery/css/images/calendar.gif',
											buttonImageOnly: true,
											showOn: 'button'
	}); 
	});
</script>